Definition at line 34 of file gps.c.
References alt, DEFAULTHOST, DEFAULTPORT, GPSD_CANT_BIND_PORT, GPSD_CANT_CONNECT, GPSD_CANT_OPEN_SOCKET, GPSD_UNKNOWN_HOST, GPSDsock, hed, last_hed, last_lat, last_lon, lat, localaddr, lon, mode, and spd.
00035 {
00036 int save_mode;
00037
00038 GPSDsock = -1;
00039 lat = lon = alt = spd = hed = 0;
00040 last_lat = last_lon = last_hed = 0;
00041 mode = -1;
00042
00043 host = strdup(DEFAULTHOST);
00044 port = DEFAULTPORT;
00045
00046
00047 h = gethostbyname(host);
00048 if (h == NULL) {
00049 return GPSD_UNKNOWN_HOST;
00050 }
00051
00052 servaddr.sin_family = h->h_addrtype;
00053 memcpy((char *) &servaddr.sin_addr.s_addr, h->h_addr_list[0],
00054 h->h_length);
00055 servaddr.sin_port = htons(port);
00056
00057
00058 if ((GPSDsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
00059 return GPSD_CANT_OPEN_SOCKET;
00060 }
00061
00062 localaddr.sin_family = AF_INET;
00063 localaddr.sin_addr.s_addr = htonl(INADDR_ANY);
00064 localaddr.sin_port = htons(0);
00065
00066 if (bind(sock, (struct sockaddr *) &localaddr, sizeof(localaddr)) < 0) {
00067 return GPSD_CANT_BIND_PORT;
00068 }
00069
00070 if (connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
00071 return GPSD_CANT_CONNECT;
00072 }
00073
00074 save_mode = fcntl(sock, F_GETFL, 0);
00075 fcntl(sock, F_SETFL, save_mode | O_NONBLOCK);
00076
00077 }