ccn_setup_sockaddr_un.c

Go to the documentation of this file.
00001 /**
00002  * @file ccn_setup_sockaddr_un.c
00003  * @brief
00004  * 
00005  * Part of the CCNx C Library.
00006  *
00007  * Copyright (C) 2009 Palo Alto Research Center, Inc.
00008  *
00009  * This library is free software; you can redistribute it and/or modify it
00010  * under the terms of the GNU Lesser General Public License version 2.1
00011  * as published by the Free Software Foundation.
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details. You should have received
00016  * a copy of the GNU Lesser General Public License along with this library;
00017  * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
00018  * Fifth Floor, Boston, MA 02110-1301 USA.
00019  */
00020  
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <sys/socket.h>
00025 #include <sys/un.h>
00026 
00027 #include <ccn/ccnd.h>
00028 #include <ccn/ccn_private.h>
00029 
00030 /**
00031  * Set up a unix-domain socket address for contacting ccnd.
00032  *
00033  * If the environment variable CCN_LOCAL_SOCKNAME is set and
00034  * not empty, it supplies the name stem; otherwise the compiled-in
00035  * default is used.
00036  *
00037  * If portstr is NULL or empty, the environment variable CCN_LOCAL_PORT is
00038  * checked. If the portstr specifies something other than the ccnx registered
00039  * port number, the socket name is modified accordingly. 
00040  * @param portstr - numeric port; use NULL for default.
00041  */
00042 void
00043 ccn_setup_sockaddr_un(const char *portstr, struct sockaddr_un *result)
00044 {
00045     struct sockaddr_un *sa = result;
00046     const char *sockname = getenv("CCN_LOCAL_SOCKNAME");
00047     if (sockname == NULL || sockname[0] == 0)
00048         sockname = CCN_DEFAULT_LOCAL_SOCKNAME; /* /tmp/.ccnd.sock */
00049     memset(sa, 0, sizeof(*sa));
00050     sa->sun_family = AF_UNIX;
00051     if (portstr == NULL || portstr[0] == 0)
00052         portstr = getenv(CCN_LOCAL_PORT_ENVNAME);
00053     if (portstr != NULL && atoi(portstr) > 0 &&
00054           atoi(portstr) != atoi(CCN_DEFAULT_UNICAST_PORT))
00055         snprintf(sa->sun_path, sizeof(sa->sun_path), "%s.%s",
00056                  sockname, portstr);
00057     else
00058         snprintf(sa->sun_path, sizeof(sa->sun_path), "%s",
00059                  sockname);
00060 }
Generated on Fri May 13 16:27:03 2011 for Content-Centric Networking in C by  doxygen 1.6.3