]>
cvs.zerfleddert.de Git - record-dvb/blob - common.c
5 #include <netinet/in.h>
11 struct dvb_host
*parse(char *urlpart
, char *defport
)
13 struct dvb_host
*dvbhost
;
16 if (!(dvbhost
= malloc(sizeof(struct dvb_host
)))) {
21 bzero(dvbhost
, sizeof(struct dvb_host
));
23 if (!(dvbhost
->hostname
= strdup(urlpart
))) {
28 /* Unneded, but better readablity: */
29 dvbhost
->location
= NULL
;
32 pos
= dvbhost
->hostname
;
34 while(*pos
!= '\0' && *pos
!= ':' && *pos
!= '/')
38 dvbhost
->location
= pos
+ 1;
41 dvbhost
->port
= pos
+ 1;
48 while(*pos
!= '\0' && *pos
!= '/')
52 dvbhost
->location
= pos
+ 1;
58 dvbhost
->port
= strdup(defport
);
60 if (!dvbhost
->location
)
61 if(!(dvbhost
->location
= strdup(""))) {
69 int resolve(struct dvb_host
*dvbhost
, struct sockaddr_in
*server
)
71 struct addrinfo
*s_addrinfo
, addrhints
;
74 bzero(&addrhints
, sizeof(struct addrinfo
));
75 addrhints
.ai_family
= PF_INET
;
76 addrhints
.ai_socktype
= dvbhost
->socktype
;
78 if ((res
= getaddrinfo(dvbhost
->hostname
, dvbhost
->port
, &addrhints
, &s_addrinfo
))) {
79 fprintf(stderr
,"getaddrinfo: %s\n",gai_strerror(res
));
83 bzero(server
, sizeof(struct sockaddr_in
));
84 server
->sin_family
= AF_INET
;
85 server
->sin_addr
.s_addr
= ((struct sockaddr_in
*)(s_addrinfo
->ai_addr
))->sin_addr
.s_addr
;
86 server
->sin_port
= ((struct sockaddr_in
*)(s_addrinfo
->ai_addr
))->sin_port
;
88 freeaddrinfo(s_addrinfo
);