荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: georgehill (New Century New Dream), 信区: Linux
标  题: [part 3] epclient.c(转寄)
发信站: BBS 荔园晨风站 (Sat Jan  6 15:21:00 2001), 站内信件

【 以下文字转载自 georgehill 的信箱 】
【 原文由 georgehill.bbs@smth.org 所发表 】
发信人: 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 荔园晨风站 bbs.szu.edu.cn·[FROM: 192.168.1.115]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店