Пример #1
0
static int get_struct_sockopt (Socket_Type *s, int level, int optname,
			       SLang_CStruct_Field_Type *cs, VOID_STAR v,
			       socklen_t len)
{
   if (-1 == do_getsockopt (s->fd, level, optname, v, &len))
     return -1;

   return SLang_push_cstruct (v, cs);
}
Пример #2
0
static int get_str_sockopt (Socket_Type *s, int level, int optname)
{
   char buf[1024];
   socklen_t len = sizeof (buf)-1;

   if (-1 == do_getsockopt (s->fd, level, optname, (void *)buf, &len))
     return -1;

   buf[len] = 0;
   return SLang_push_string (buf);
}
Пример #3
0
static int get_int_sockopt (Socket_Type *s, int level, int optname)
{
   int val;
   socklen_t len;

   len = sizeof (int);
   if (-1 == do_getsockopt (s->fd, level, optname, (void *)&val, &len))
     return -1;

   return SLang_push_int (val);
}
Пример #4
0
static int
get_set_byname(const char *setname, struct xt_set_info *info)
{
	struct ip_set_req_get_set req;
	int res;

	req.op = IP_SET_OP_GET_BYNAME;
	strncpy(req.set.name, setname, IPSET_MAXNAMELEN);
	req.set.name[IPSET_MAXNAMELEN - 1] = '\0';
	res = do_getsockopt(&req);
	if (res != 0)
		return -1;
	if (req.set.index == IPSET_INVALID_ID)
		return -1;
	info->index = req.set.index;
	return 0;
}
Пример #5
0
static int
get_set_byid(char *setname, unsigned int idx)
{
	struct ip_set_req_get_set req;
	int res;

	req.op = IP_SET_OP_GET_BYINDEX;
	req.set.index = idx;
	res = do_getsockopt(&req);
	if (res != 0)
		return -1;
	if (req.set.name[0] == '\0') {
		fprintf(stderr,
			"Set with index %i in kernel doesn't exist.\n", idx);
		return -1;
	}

	strncpy(setname, req.set.name, IPSET_MAXNAMELEN);
	return 0;
}