mirror of
https://github.com/linux-can/can-utils.git
synced 2026-08-05 06:20:00 +02:00
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>
This commit is contained in:
committed by
Oleksij Rempel
parent
0ff988eeef
commit
1ba9b86451
+20
-2
@@ -38,6 +38,7 @@ static const char help_msg[] =
|
|||||||
" This atually receives packets\n"
|
" This atually receives packets\n"
|
||||||
" -c Issue connect()\n"
|
" -c Issue connect()\n"
|
||||||
" -p=PRIO Set priority to PRIO\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"
|
" -n Emit 64bit NAMEs in output\n"
|
||||||
" -w[TIME] Return after TIME (default 1) seconds\n"
|
" -w[TIME] Return after TIME (default 1) seconds\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -46,7 +47,7 @@ static const char help_msg[] =
|
|||||||
"\n"
|
"\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)
|
static void parse_canaddr(char *spec, struct sockaddr_can *paddr)
|
||||||
{
|
{
|
||||||
@@ -109,7 +110,7 @@ int main(int argc, char *argv[])
|
|||||||
uint8_t dat[128];
|
uint8_t dat[128];
|
||||||
int valid_peername = 0;
|
int valid_peername = 0;
|
||||||
int todo_send = 0, todo_recv = 0, todo_echo = 0, todo_prio = -1;
|
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 */
|
/* argument parsing */
|
||||||
while ((opt = getopt(argc, argv, optstring)) != -1)
|
while ((opt = getopt(argc, argv, optstring)) != -1)
|
||||||
@@ -135,6 +136,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'n':
|
case 'n':
|
||||||
todo_names = 1;
|
todo_names = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'b':
|
||||||
|
todo_rebind = 1;
|
||||||
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
schedule_oneshot_itimer(strtod(optarg ?: "1", NULL));
|
schedule_oneshot_itimer(strtod(optarg ?: "1", NULL));
|
||||||
signal(SIGALRM, onsigalrm);
|
signal(SIGALRM, onsigalrm);
|
||||||
@@ -152,6 +156,9 @@ int main(int argc, char *argv[])
|
|||||||
++optind;
|
++optind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (todo_rebind)
|
||||||
|
sockname.can_addr.j1939.addr++;
|
||||||
|
|
||||||
if (argv[optind]) {
|
if (argv[optind]) {
|
||||||
if (strcmp("-", argv[optind])) {
|
if (strcmp("-", argv[optind])) {
|
||||||
parse_canaddr(argv[optind], &peername);
|
parse_canaddr(argv[optind], &peername);
|
||||||
@@ -182,6 +189,17 @@ int main(int argc, char *argv[])
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
error(1, errno, "bind()");
|
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 (todo_connect) {
|
||||||
if (!valid_peername)
|
if (!valid_peername)
|
||||||
error(1, 0, "no peername supplied");
|
error(1, 0, "no peername supplied");
|
||||||
|
|||||||
Reference in New Issue
Block a user