|
From: Peter K. <pk...@us...> - 2001-04-11 12:23:46
|
The following file was modified in apps/bluetooth/btd:
Name Old version New version Comment
---- ----------- ----------- -------
btd.c 1.89 1.90=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
open_tcpsocket() no longer crashes if there is no colon in
the address string. Instead it terminates the program
(thanks to Salil Gokhale for finding this).
The diff of the modified file(s):
--- btd.c 2001/03/30 12:49:06 1.89
+++ btd.c 2001/04/11 12:23:45 1.90
@@ -851,7 +851,7 @@
/* check if there is a server available */
if (! use_ipassign)
{
- if ((ipa_sock =3D open_socket(SRVSOCKET, CLIENT)))
+ if ((ipa_sock =3D open_socket(SRVSOCKET, CLIENT)) >=3D 0)
{
syslog(LOG_INFO, "IP Assign server OK.\n");
close_device(ipa_sock);
@@ -2332,8 +2332,7 @@
=20=20=20
if ((n =3D write(pty_master_fd, data, len)) !=3D len)
{
- BT_DATA("bt_receive_top: tried to write %d bytes, wrote %d\n",
- len, n);
+ BT_DATA("bt_receive_top: tried to write %d bytes, wrote %d\n", len, n);
}
=20
bt_stat.bytes_received+=3Dn;
@@ -2360,7 +2359,6 @@
line =3D GET_RFCOMMLINE(con_id);
=20=20=20=20=20=20=20=20=20=20=20
if ((line < 0) || (line > BT_NBR_DATAPORTS)) {
-=20=20=20=20=20=20=20=20=20=20=20=20
printf("bt_connect_cfm on invalid line (%d)\n", line);
return;
}
@@ -2371,10 +2369,8 @@
=20=09
switch (psm) {
case RFCOMM_LAYER:
- {=09
printf("bt_connect_cfm [%s]\n", psmname(psm));
break;
- }
=20=20=20=20=20=20=20=20=20=20=20
case SDP_LAYER:
printf("bt_connect_cfm [%s]\n", psmname(psm));
@@ -2436,11 +2432,16 @@
=20=20=20
/*parse address string */
=20
- pos =3D strchr(addrstr, ':');
+ if (!(pos =3D strchr(addrstr, ':')))
+ {
+ fprintf(stderr, "Port argument missing!\n");
+ exit(1);
+ }
=20
/* copy ip address */
- memcpy(ipstr, addrstr, pos-addrstr);
- ipstr[pos-addrstr]=3D0; /* null term */
+ *pos =3D '\0';
+ strncpy(ipstr, addrstr, sizeof ipstr);
+ ipstr[sizeof ipstr - 1] =3D '\0';
=20
/* extract port number */
port =3D atoi(pos+1);
@@ -2472,9 +2473,6 @@
client_sockfd =3D accept(server_sockfd,
(struct sockaddr *)&(client_address),
&client_len);
-=20=20=20=20
- return client_sockfd;
-
}
else
{
@@ -2497,10 +2495,10 @@
perror("open_tcpsocket");
exit(1);
}
+ }
=20
return client_sockfd;
}
-}
=20
#endif /* BTD_USERSTACK */
=20
@@ -2530,8 +2528,6 @@
client_sockfd =3D accept(server_sockfd,=20
(struct sockaddr *)&(client_address),
&client_len);
-=20=20=20=20
- return client_sockfd;
}
else
{
@@ -2547,13 +2543,13 @@
(struct sockaddr *)&server_address,=20
server_len) < 0) {
syslog(LOG_ERR, "open_socket %s failed", name);
- return 0;
+ return -1;
}
=20
-
syslog(LOG_INFO, "Socket connected to %s\n", server_address.sun_path);
- return client_sockfd;
}
+
+ return client_sockfd;
}
=20
#ifdef USE_IPASSIGN
@@ -2565,7 +2561,7 @@
=20=20=20
syslog(LOG_INFO, "Opening socket to IP Assigner\n");
=20=20=20
- if (!(ipa_sock =3D open_socket(SRVSOCKET, CLIENT)))
+ if ((ipa_sock =3D open_socket(SRVSOCKET, CLIENT)) < 0)
{=20=20
perror("open_socket");
return NULL;
@@ -2748,7 +2744,6 @@
switch (layer)
{
case MSG_LAYER_HCI:
- {
switch(code)
{=20=20=20=20=20=20=20
case 4:=20=20=20=20=20=20=20=20
@@ -2757,11 +2752,9 @@
return "HCI - Unknown reason";
break;
}
- }
break;
=20=20=20=20=20
case MSG_LAYER_L2CAP:
- {
switch(code)
{=20
case RES_PSMNEG:
@@ -2773,7 +2766,6 @@
default:
return "L2CAP - unknown reason";
}
- }
break;
=20=20=20=20=20
default:
@@ -2807,7 +2799,8 @@
/* only connects rfcomm (as client) currently */
if (GET_PSM(con_id) =3D=3D RFCOMM_LAYER)
con.id =3D con_id;
- else{=20=20
+ else
+ {
printf("Only connects rfcomm as client !\n");
return ;
}
@@ -2826,7 +2819,8 @@
srv_ch =3D GET_RFCOMMSRVCH(con_id);
line =3D GET_RFCOMMLINE(con_id);
=20=20
- if (line !=3D 0) {
+ if (line !=3D 0)
+ {
printf("Use line 0 instead ! (usermode only)\n");
return;
}
@@ -2854,7 +2848,8 @@
CHECK_RFCOMM(con_id);
line =3D GET_RFCOMMLINE(con_id);
=20=20=20
- if (line !=3D 0) {
+ if (line !=3D 0)
+ {
printf("Use line 0 instead ! (usermode only)\n");
return;
}
@@ -2982,8 +2977,8 @@
for (i =3D 0; i < 6; i++) {
bd_addr[i] =3D rev_bd[5-i];
}
-
#endif
+
printf("Current bd addr : %02X:%02X:%02X:%02X:%02X:%02X\n",
bd_addr[0], bd_addr[1], bd_addr[2],
bd_addr[3], bd_addr[4], bd_addr[5]);
@@ -3025,8 +3020,8 @@
for (i =3D 0; i < 6; i++) {
bd_addr[i] =3D rev_bd[5-i];
}
-
#endif
+
printf("Client bd addr : %02X:%02X:%02X:%02X:%02X:%02X\n",
bd_addr[0], bd_addr[1], bd_addr[2],
bd_addr[3], bd_addr[4], bd_addr[5]);
@@ -3326,7 +3321,7 @@
=20
/*********************************************************************/
/***************** Ericsson test functions ***************************/
-/******************This will be moved later **************************/
+/***************** This will be moved later **************************/
/*********************************************************************/
=20
#ifdef ECS_TEST_FUNCTIONS
|