BBS水木清华站∶精华区

发信人: althea (稻草人), 信区: Linux        
标  题: [part 3] epclient.c 
发信站: BBS 水木清华站 (Fri Dec 29 23:51:41 2000) 
 
#include <unistd.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <errno.h> 
#include <sys/socket.h> 
#include <sys/un.h> 
 
 
int main() 

    char *display_name; 
    char socket_file_name[64]; 
    int  sock; 
    struct sockaddr_un name; 
    size_t nbytes, size; 
 
    nbytes = strlen (getenv("DISPLAY")); 
    if (nbytes<=0) { 
        perror ("DISPLAY"); 
        exit (1); 
    } 
 
    display_name = malloc (nbytes+1); 
    sprintf (display_name, "%s\n", getenv("DISPLAY"));  
 
    /* Create the socket. */ 
    sock = socket (PF_LOCAL, SOCK_DGRAM, 0); 
    if (sock < 0) 
    { 
        perror ("socket"); 
        exit (EXIT_FAILURE); 
    } 
 
    snprintf (socket_file_name, 64, "/tmp/ep-%d", (int) geteuid()); 
    name.sun_family = AF_LOCAL; 
    strncpy (name.sun_path, socket_file_name, sizeof (name.sun_path)); 
    size = SUN_LEN (&name); 
 
    if (sendto (sock, display_name, nbytes+1, 0, &name, size) < 0) { 
        perror ("sendto"); 
        exit (1); 
    } 
 
    return 0; 

 
 
-- 
Look Ma, this man can twist his fingers as if they were made of rubber, 
isn't that amazing? -- Not really, he's been using emacs for years...! 
 
 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 162.105.203.100] 

BBS水木清华站∶精华区