Check-in [0bbc3f5bba]
Overview
Comment:Updated to support addresses specified in IPv4 style (in which case only IPv4 is used)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0bbc3f5bbac994fdb65c688a5cd151db82e30da0
User & Date: rkeene on 2014-02-08 03:36:30
Other Links: manifest | tags
Context
2014-02-08
03:55
Added README check-in: ab9592633a user: rkeene tags: trunk
03:36
Updated to support addresses specified in IPv4 style (in which case only IPv4 is used) check-in: 0bbc3f5bba user: rkeene tags: trunk
03:17
Updated to more safely generate mimetypes file check-in: cbe7d25150 user: rkeene tags: trunk
Changes

Modified filed.c from [6f13628165] to [5e70bdaf5f].

   144    144   	}
   145    145   
   146    146   	return(0);
   147    147   }
   148    148   
   149    149   /* Listen on a particular address/port */
   150    150   static int filed_listen(const char *address, unsigned int port) {
   151         -	struct sockaddr_in6 addr;
          151  +	struct sockaddr_in6 addr_v6;
          152  +	struct sockaddr_in addr_v4;
          153  +	struct sockaddr *addr;
          154  +	socklen_t addr_len;
   152    155   	int pton_ret, bind_ret, listen_ret;
          156  +	int family;
   153    157   	int fd;
   154    158   
   155         -	addr.sin6_family = AF_INET6;
   156         -	addr.sin6_flowinfo = 0;
   157         -	addr.sin6_scope_id = 0;
   158         -	addr.sin6_port = htons(port);
   159         -	pton_ret = inet_pton(AF_INET6, address, addr.sin6_addr.s6_addr);
          159  +
          160  +	family = AF_INET6;
          161  +	pton_ret = inet_pton(family, address, &addr_v6.sin6_addr.s6_addr);
   160    162   	if (pton_ret != 1) {
   161         -		return(-1);
          163  +		family = AF_INET;
          164  +		pton_ret = inet_pton(family, address, &addr_v4.sin_addr.s_addr);
          165  +		if (pton_ret != 1) {
          166  +			return(-1);
          167  +		}
          168  +
          169  +		addr_v4.sin_family = family;
          170  +		addr_v4.sin_port = htons(port);
          171  +
          172  +		addr = (struct sockaddr *) &addr_v4;
          173  +		addr_len = sizeof(addr_v4);
          174  +	} else {
          175  +		addr_v6.sin6_family = AF_INET6;
          176  +		addr_v6.sin6_flowinfo = 0;
          177  +		addr_v6.sin6_scope_id = 0;
          178  +		addr_v6.sin6_port = htons(port);
          179  +
          180  +		addr = (struct sockaddr *) &addr_v6;
          181  +		addr_len = sizeof(addr_v6);
   162    182   	}
   163    183   
   164         -	fd = socket(AF_INET6, SOCK_STREAM, 0);
          184  +	fd = socket(family, SOCK_STREAM, 0);
   165    185   	if (fd < 0) {
   166    186   		return(fd);
   167    187   	}
   168    188   
   169         -	bind_ret = bind(fd, (const struct sockaddr *) &addr, sizeof(addr));
          189  +	bind_ret = bind(fd, addr, addr_len);
   170    190   	if (bind_ret < 0) {
   171    191   		close(fd);
   172    192   
   173    193   		return(-1);
   174    194   	}
   175    195   
   176    196   	listen_ret = listen(fd, 128);