/* test of auth_user/server_authenticate: send part Copyright (C) 2015 Free Software Foundation, Inc. Written by Svante Signell . This file is part of the GNU Hurd. The GNU Hurd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Hurd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the GNU Hurd. If not, see . */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #define SOCK_PATH "auth_socket" int main (void) { mach_port_t rendezvous = __mach_reply_port (); mach_port_t newport = NULL; error_t err; int sfd; struct sockaddr_un addr = { 0 }; int data = 12345; char sbuf[30]; vm_size_t ns = -1; mach_port_t ports[1]; addr.sun_family = AF_UNIX; strncpy(addr.sun_path, SOCK_PATH, sizeof(addr.sun_path) - 1); #ifdef USE_SOCK_DGRAM sfd = socket (AF_UNIX, SOCK_DGRAM, 0); #else sfd = socket (AF_UNIX, SOCK_STREAM, 0); #endif if (sfd == -1) { perror ("socket"); exit(EXIT_FAILURE); } printf("auth_socket_send.c: Socket file descriptor = %d\n", sfd); if (connect(sfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) == -1) { close(sfd); perror ("connect"); exit(EXIT_FAILURE); } #ifdef USE_SOCK_DGRAM printf("auth_socket_send.c: Sending via datagram socket\n"); #else fprintf(stderr, "Sending via stream socket\n"); #endif printf ("auth_socket_send.c: rendezvous port = %d\n", (int)rendezvous); err = mach_port_insert_right (mach_task_self (), rendezvous, rendezvous, MACH_MSG_TYPE_MAKE_SEND); if (err) { printf ("auth_socket_send.c: mach_port_insert_right() err = %d\n", err); goto out; } printf("auth_socket_send.c: Sent data = %d\n", data); sprintf(sbuf, "%d", data); ports[0] = rendezvous; err = HURD_DPORT_USE (sfd, __socket_send (port, MACH_PORT_NULL, 0, sbuf, sizeof(sbuf), ports, MACH_MSG_TYPE_COPY_SEND, 1, NULL, 0, &ns)); if (err) { printf("auth_socket_send.c: __socket_send() err = %d \n", err); return err; } if (ns == -1) { perror ("__socket_send"); exit(EXIT_FAILURE); } printf("auth_socket_send.c: __socket_send() returned %ld bytes\n", (long) ns); err = __USEPORT (AUTH, auth_user_authenticate (port, rendezvous, MACH_MSG_TYPE_MAKE_SEND, &newport)); out: printf ("auth_socket_send.c: auth_user_authenticate(): Received newport = %d\n", (int)newport); __mach_port_deallocate (__mach_task_self (), rendezvous); __mach_port_deallocate (__mach_task_self (), newport); if (err) printf ("auth_socket_send.c: err = %d\n", err); return err; }