Home | History | Annotate | Download | only in tests-mx32
      1 /*
      2  * Copyright (c) 2017 JingPiao Chen <chenjingpiao (at) gmail.com>
      3  * Copyright (c) 2017 The strace developers.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include "tests.h"
     30 #include <stdio.h>
     31 #include <sys/socket.h>
     32 #include "netlink.h"
     33 
     34 int
     35 main(void)
     36 {
     37 	skip_if_unavailable("/proc/self/fd/");
     38 
     39 	long rc;
     40 	int fd = create_nl_socket(NETLINK_KOBJECT_UEVENT);
     41 
     42 	/* test using data that looks like a zero-length C string */
     43 	char *const buf = tail_alloc(DEFAULT_STRLEN + 1);
     44 	buf[0] = '=';
     45 	fill_memory_ex(buf + 1, DEFAULT_STRLEN, 0, DEFAULT_STRLEN);
     46 
     47 	rc = sendto(fd, buf + 1, DEFAULT_STRLEN, MSG_DONTWAIT, NULL, 0);
     48 	printf("sendto(%d, ", fd);
     49 	print_quoted_memory(buf + 1, DEFAULT_STRLEN);
     50 	printf(", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
     51 	       DEFAULT_STRLEN, sprintrc(rc));
     52 
     53 	rc = sendto(fd, buf, DEFAULT_STRLEN + 1, MSG_DONTWAIT, NULL, 0);
     54 	printf("sendto(%d, ", fd);
     55 	print_quoted_memory(buf, DEFAULT_STRLEN);
     56 	printf("..., %u, MSG_DONTWAIT, NULL, 0) = %s\n",
     57 	       DEFAULT_STRLEN + 1, sprintrc(rc));
     58 
     59 	puts("+++ exited with 0 +++");
     60 	return 0;
     61 }
     62