Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/csping.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* ping host by name
26
*/
27
28
#include "cslib.h"
29
30
#define M "yo\n"
31
#define N (sizeof(M)-1)
32
33
int
34
csping(register Cs_t* state, const char* name)
35
{
36
register int fd;
37
register int n;
38
39
sfsprintf(state->temp, sizeof(state->path), "/dev/tcp/%s/inet.echo", name);
40
if ((fd = csopen(state, state->temp, 0)) < 0) return -1;
41
n = (cswrite(state, fd, M, N) != N || csread(state, fd, state->temp, N, CS_LINE) != N || strncmp(M, state->temp, N)) ? -1 : 0;
42
close(fd);
43
if (n) messagef((state->id, NiL, -1, "ping: %s: no contact", name));
44
return n;
45
}
46
47
int
48
_cs_ping(const char* name)
49
{
50
return csping(&cs, name);
51
}
52
53