-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpt.c
42 lines (37 loc) · 761 Bytes
/
hpt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Parse [host]/port[/ttl]. Return 0 if ok, -1 if error; set sockaddr and
* ttl value.
*/
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "sysdep.h"
extern struct in_addr host2ip(char *);
int hpt(char *h, struct sockaddr *sa, unsigned char *ttl)
{
char *s;
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
sin->sin_family = AF_INET;
/* first */
s = strchr(h, '/');
if (!s) {
return -1;
}
else {
int port;
*s = '\0';
port = atoi(s+1);
sin->sin_port = htons(port);
if (port & 1) {
return -2;
}
s = strchr(s+1, '/');
if (s && ttl) {
*ttl = atoi(s+1);
}
sin->sin_addr = host2ip(h);
}
return 0;
} /* hpt */