testj1939: add re-bind support
This option is needed for j1939 socket functionality test. Binding to a socket and rebinding to the socket with e.g. a different SA should work. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Bastian Stender <bst@pengutronix.de>pull/101/head
parent
0ff988eeef
commit
1ba9b86451
22
testj1939.c
22
testj1939.c
|
|
@ -38,6 +38,7 @@ static const char help_msg[] =
|
|||
" This atually receives packets\n"
|
||||
" -c Issue connect()\n"
|
||||
" -p=PRIO Set priority to PRIO\n"
|
||||
" -b Do normal bind with SA+1 and rebind with actual SA\n"
|
||||
" -n Emit 64bit NAMEs in output\n"
|
||||
" -w[TIME] Return after TIME (default 1) seconds\n"
|
||||
"\n"
|
||||
|
|
@ -46,7 +47,7 @@ static const char help_msg[] =
|
|||
"\n"
|
||||
;
|
||||
|
||||
static const char optstring[] = "?vs::rep:cnw::";
|
||||
static const char optstring[] = "?vbs::rep:cnw::";
|
||||
|
||||
static void parse_canaddr(char *spec, struct sockaddr_can *paddr)
|
||||
{
|
||||
|
|
@ -109,7 +110,7 @@ int main(int argc, char *argv[])
|
|||
uint8_t dat[128];
|
||||
int valid_peername = 0;
|
||||
int todo_send = 0, todo_recv = 0, todo_echo = 0, todo_prio = -1;
|
||||
int todo_connect = 0, todo_names = 0, todo_wait = 0;
|
||||
int todo_connect = 0, todo_names = 0, todo_wait = 0, todo_rebind = 0;
|
||||
|
||||
/* argument parsing */
|
||||
while ((opt = getopt(argc, argv, optstring)) != -1)
|
||||
|
|
@ -135,6 +136,9 @@ int main(int argc, char *argv[])
|
|||
case 'n':
|
||||
todo_names = 1;
|
||||
break;
|
||||
case 'b':
|
||||
todo_rebind = 1;
|
||||
break;
|
||||
case 'w':
|
||||
schedule_oneshot_itimer(strtod(optarg ?: "1", NULL));
|
||||
signal(SIGALRM, onsigalrm);
|
||||
|
|
@ -152,6 +156,9 @@ int main(int argc, char *argv[])
|
|||
++optind;
|
||||
}
|
||||
|
||||
if (todo_rebind)
|
||||
sockname.can_addr.j1939.addr++;
|
||||
|
||||
if (argv[optind]) {
|
||||
if (strcmp("-", argv[optind])) {
|
||||
parse_canaddr(argv[optind], &peername);
|
||||
|
|
@ -182,6 +189,17 @@ int main(int argc, char *argv[])
|
|||
if (ret < 0)
|
||||
error(1, errno, "bind()");
|
||||
|
||||
if (todo_rebind) {
|
||||
/* rebind with actual SA */
|
||||
sockname.can_addr.j1939.addr--;
|
||||
|
||||
if (verbose)
|
||||
fprintf(stderr, "- bind(, %s, %zi);\n", libj1939_addr2str(&sockname), sizeof(sockname));
|
||||
ret = bind(sock, (void *)&sockname, sizeof(sockname));
|
||||
if (ret < 0)
|
||||
error(1, errno, "re-bind()");
|
||||
}
|
||||
|
||||
if (todo_connect) {
|
||||
if (!valid_peername)
|
||||
error(1, 0, "no peername supplied");
|
||||
|
|
|
|||
Loading…
Reference in New Issue