]>
cvs.zerfleddert.de Git - record-dvb/blob - common.c
5 #include <netinet/in.h>
11 struct dvb_host
*parse(char *urlpart
, char *defport
)
13 static struct dvb_host
*dvbhost
= NULL
;
17 if (!(dvbhost
= malloc(sizeof(struct dvb_host
)))) {
23 bzero(dvbhost
, sizeof(struct dvb_host
));
25 if (!(dvbhost
->hostname
= strdup(urlpart
))) {
30 /* Unneded, but better readablity: */
31 dvbhost
->location
= NULL
;
34 pos
= dvbhost
->hostname
;
36 while(*pos
!= '\0' && *pos
!= ':' && *pos
!= '/')
40 dvbhost
->location
= pos
+ 1;
43 dvbhost
->port
= pos
+ 1;
50 while(*pos
!= '\0' && *pos
!= '/')
54 dvbhost
->location
= pos
+ 1;
60 dvbhost
->port
= strdup(defport
);
62 if (!dvbhost
->location
)
63 if(!(dvbhost
->location
= strdup(""))) {
71 int resolve(struct dvb_host
*dvbhost
, struct sockaddr_in
*server
)
73 struct addrinfo
*s_addrinfo
, addrhints
;
76 bzero(&addrhints
, sizeof(struct addrinfo
));
77 addrhints
.ai_family
= PF_INET
;
78 addrhints
.ai_socktype
= dvbhost
->socktype
;
80 if ((res
= getaddrinfo(dvbhost
->hostname
, dvbhost
->port
, &addrhints
, &s_addrinfo
))) {
81 fprintf(stderr
,"getaddrinfo: %s\n",gai_strerror(res
));
85 bzero(server
, sizeof(struct sockaddr_in
));
86 server
->sin_family
= AF_INET
;
87 server
->sin_addr
.s_addr
= ((struct sockaddr_in
*)(s_addrinfo
->ai_addr
))->sin_addr
.s_addr
;
88 server
->sin_port
= ((struct sockaddr_in
*)(s_addrinfo
->ai_addr
))->sin_port
;
90 freeaddrinfo(s_addrinfo
);
95 int is_url(char *string
)
99 if (!(strlen(string
)))
104 while(*pos
!= ':' && *pos
!= 0)
107 if (!strncmp("://", pos
, 3))