ClientCollectors/ARODataCollector/external/libpcap-1.1.1/nametoaddr.c
int
pcap_nametoportrange(const char *name, int *port1, int *port2, int *proto)
{
	u_int p1, p2;
	char *off, *cpy;
	int save_proto;

	if (sscanf(name, "%d-%d", &p1, &p2) != 2) {
		if ((cpy = strdup(name)) == NULL)
			return 0;

		if ((off = strchr(cpy, '-')) == NULL) {
			free(cpy);
			return 0;
		}

		*off = '\0';

		if (pcap_nametoport(cpy, port1, proto) == 0) {
			free(cpy);
			return 0;
		}
		save_proto = *proto;

		if (pcap_nametoport(off + 1, port2, proto) == 0) {
			free(cpy);
			return 0;
		}

		if (*proto != save_proto)
			*proto = PROTO_UNDEF;
	} else {
		*port1 = p1;
		*port2 = p2;
		*proto = PROTO_UNDEF;
	}

	return 1;
}
/*
 * Convert a string in the form PPP-PPP, where correspond to ports, to
 * a starting and ending port in a port range.
 * Return 0 on failure.
 */
Convert a string in the form PPP-PPP, where correspond to ports, to
a starting and ending port in a port range.
Return 0 on failure.
Convert a string in the form PPP - PPP where correspond to ports to a starting and ending port in a port range . Return 0 on failure .
int
pcap_nametoportrange(const char *name, int *port1, int *port2, int *proto)
{
	u_int p1, p2;
	char *off, *cpy;
	int save_proto;
	if (sscanf(name, "%d-%d", &p1, &p2) != 2) {
		if ((cpy = strdup(name)) == NULL)
			return 0;
		if ((off = strchr(cpy, '-')) == NULL) {
			free(cpy);
			return 0;
		}
		*off = '\0';
		if (pcap_nametoport(cpy, port1, proto) == 0) {
			free(cpy);
			return 0;
		}
		save_proto = *proto;
		if (pcap_nametoport(off + 1, port2, proto) == 0) {
			free(cpy);
			return 0;
		}
		if (*proto != save_proto)
			*proto = PROTO_UNDEF;
	} else {
		*port1 = p1;
		*port2 = p2;
		*proto = PROTO_UNDEF;
	}
	return 1;
}
int pcap_nametoportrange ( const char * name , int * port1 , int * port2 , int * proto ) { u_int p1 , p2 ; char * off , * cpy ; int save_proto ; if ( sscanf ( name , " " , & p1 , & p2 ) != 2 ) { if ( ( cpy = strdup ( name ) ) == NULL ) return 0 ; if ( ( off = strchr ( cpy , ' ' ) ) == NULL ) { free ( cpy ) ; return 0 ; } * off = ' \0 ' ; if ( pcap_nametoport ( cpy , port1 , proto ) == 0 ) { free ( cpy ) ; return 0 ; } save_proto = * proto ; if ( pcap_nametoport ( off + 1 , port2 , proto ) == 0 ) { free ( cpy ) ; return 0 ; } if ( * proto != save_proto ) * proto = PROTO_UNDEF ; } else { * port1 = p1 ; * port2 = p2 ; * proto = PROTO_UNDEF ; } return 1 ; }
Convert a string in the form PPP-PPP, where correspond to ports, to
 a starting and ending port in a port range.
Convert a string in the form PPP - PPP where correspond to ports to a starting and ending port in a port range .