]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - gnu/libexec/uucp/libunix/portnm.c
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / gnu / libexec / uucp / libunix / portnm.c
1 /* portnm.c
2    Get the port name of stdin.  */
3
4 #include "uucp.h"
5
6 #include "sysdep.h"
7 #include "system.h"
8
9 #if HAVE_TCP
10 #if HAVE_SYS_TYPES_TCP_H
11 #include <sys/types.tcp.h>
12 #endif
13 #include <sys/socket.h>
14 #endif
15
16 #ifndef ttyname
17 extern char *ttyname ();
18 #endif
19
20 /* Get the port name of standard input.  I assume that Unix systems
21    generally support ttyname.  If they don't, this function can just
22    return NULL.  It uses getsockname to see whether standard input is
23    a TCP connection.  */
24
25 const char *
26 zsysdep_port_name (ftcp_port)
27      boolean *ftcp_port;
28 {
29   const char *z;
30
31   *ftcp_port = FALSE;
32
33 #if HAVE_TCP
34   {
35     size_t clen;
36     struct sockaddr s;
37
38     clen = sizeof (struct sockaddr);
39     if (getsockname (0, &s, &clen) == 0)
40       *ftcp_port = TRUE;
41   }
42 #endif /* HAVE_TCP */
43
44   z = ttyname (0);
45   if (z == NULL)
46     return NULL;
47   if (strncmp (z, "/dev/", sizeof "/dev/" - 1) == 0)
48     return z + sizeof "/dev/" - 1;
49   else
50     return z;
51 }