我目前正在开展一个学校项目,要求我实现DNS客户端,而不使用任何库函数.
我已经到了发送DNS请求并收到回复的地步.我在解析回复时遇到了困难.我在char*数组中收到回复,我想将其转换为一些有意义的结构,我可以从中解析答案.我浏览了RFC并阅读了有关数据包结构的内容,但在C中实现它会给我带来麻烦.
任何人都可以用C语言给我任何例子,或者用任何其他语言来解释这是如何完成的.或者对书的任何引用也没关系.
额外细节:
所以,以下是我正在使用的结构.
struct result{
int type;
struct res_ip_cname ip_cname;
struct res_error error;
struct res_mx_ns mx_ns;
};
struct res_ip_cname{
char* lst;
int sec;
char* auth_flag;
};
struct res_error{
char * info;
};
struct res_mx_ns{
char * name;
unsigned short pref;
int sec;
char* auth_flag;
};
Run Code Online (Sandbox Code Playgroud)
我有一个char*buffer [],其中我存储了我从服务器收到的响应.并且,我需要从此缓冲区中提取信息并填充结构结果.
谢谢,Chander
我只是在查看ConcurrentDictionary的MSDN文档,我在"示例"代码中看到了这一点:
// We know how many items we want to insert into the ConcurrentDictionary.
// So set the initial capacity to some prime number above that, to ensure that
// the ConcurrentDictionary does not need to be resized while initializing it.
int NUMITEMS = 64;
int initialCapacity = 101;
Run Code Online (Sandbox Code Playgroud)
作为参考,MSDN示例中的字典初始化如下:
ConcurrentDictionary<int, int> cd = new ConcurrentDictionary<int, int>(Environment.ProcessorCount * 2, initialCapacity);
for (int i = 0; i < NUMITEMS; i++) cd[i] = i * i;
Run Code Online (Sandbox Code Playgroud)
在该示例中,字典永远不会包含超过64个项目.为什么不将初始容量设置为64,而不是设置为大于64的看似随意的素数?评论说这是为了确保字典在初始化时不需要调整大小,但为什么需要调整initialCapacity = …
是否可以格式化stat的时间输出?我在用
stat -c '%n %A %z' $filename
Run Code Online (Sandbox Code Playgroud)
在bash脚本中,但它的时间格式不是我想要的.是否可以在命令中更改此格式,或者我必须稍后手动执行此操作?
示例输出如下:
/lib drwxr-xr-x 2010-11-15 04:02:38.000000000 -0800
Run Code Online (Sandbox Code Playgroud) 有谁知道为什么这不起作用.它将始终打印'未选中'.
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function msg(x)
{
if($(x).attr('checked')){
alert('checked!!');
}
else{
alert('unchecked');
}
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="fname2" onClick="msg(this.id)" /><br/>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我想要做的是:我希望我的应用程序从Internet下载图像并将其保存到手机的内部存储器中,该位置是应用程序专用的位置.如果列表项没有可用的图像(即无法在Internet上找到),我想要显示默认的占位符图像.这是我在list_item_row.xml文件中定义的默认图像.
在我的ListActivity文件中,我正在调用我编写的CustomCursorAdapter类的实例.它在CustomCursorAdapter中,我遍历所有列表项并定义需要映射到视图的内容,包括尝试从内部存储器读取它的图像文件.
我已经看到了关于这个主题的几个问题,但这些例子要么特定于外部手机内存(例如SDCard),涉及保存字符串而不是图像,要么涉及使用Bitmap.CompressFormat来降低文件的分辨率(这是不必要的)我的情况,因为这些图像将是已经很小分辨率的小缩略图).试图将每个示例中的代码拼凑起来一直很困难,因此我询问了我的具体示例.
目前,我相信我已经编写了有效的代码,但没有显示我的列表项的图像,包括默认的占位符图像.我不知道问题是由无效的下载/保存代码或无效的读取代码引起的 - 我不知道如何检查内部存储器以查看图像是否存在.
无论如何,这是我的代码.任何帮助将不胜感激.
ProductUtils.java
public static String productLookup(String productID, Context c) throws IOException {
URL url = new URL("http://www.samplewebsite.com/" + productID + ".jpg");
URLConnection connection = url.openConnection();
InputStream input = connection.getInputStream();
FileOutputStream output =
c.openFileOutput(productID + "-thumbnail.jpg", Context.MODE_PRIVATE);
byte[] data = new byte[1024];
output.write(data);
output.flush();
output.close();
input.close();
}
Run Code Online (Sandbox Code Playgroud)
CustomCursorAdapter.java
public class CustomCursorAdapter extends CursorAdapter {
public CustomCursorAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ImageView thumbnail …Run Code Online (Sandbox Code Playgroud) 在C中,你可以在realloc里面重新分配吗?例如,当您需要对它们两者进行malloc并重新分配它们时,结构中的结构.如果是,有人可以提供一个简单的例子吗?先感谢您.
在C#或.net IL中是否有办法强制一个具有类型初始值设定项(静态构造函数)的类来加载自身,而不访问它的任何参数?
假设我上了课
public static class LogInitialization {
static LogInitialization() {
System.Console.WriteLine("Initialized");
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让这条线打印出来?
请注意,该类是静态的,因此我无法将其实例化以强制初始化,并且它没有公共成员,因此我无法访问它们以启动它.
我想访问www.thisdomain.com/docs/path1/path2重定向到www.thatdomain.com/path1/path2
(请注意,docs不是新路径的一部分)
我在www.thisdomain.com上有以下内容:
RewriteEngine on
RewriteRule ^docs/* http://www.domain.com/ [R=301,L]
Run Code Online (Sandbox Code Playgroud)
如果我访问www.thisdomain.com/docs,它会指向www.thatdomain.com,但如果我访问像www.thisdomain.com/docs/path1/path2这样的子路径则会失败.是否可以根据需要重定向拦截子路径访问和重定向?如果是这样,任何指针?
谢谢.
我见过两个可以自定义锁屏的应用程序:Widget locker,slidecreen.我们真的有一个API可以让我们自定义锁屏吗?
如果没有,诀窍是什么?
我有一个数据网格,显示带有两列文本行数据的项目和一个更大的自由文本细节,我通过一个只带边框和文本块的rowdetails模板显示.
我遇到的问题是文本细节通常大于网格允许的区域.数据网格的默认滚动行为意味着当滚动跳转到下一个项目时,用户无法查看整个细节.如果我通过使用解决这个问题
ScrollViewer.CanContentScroll="False"
Run Code Online (Sandbox Code Playgroud)
然后,当关闭虚拟化时,数据网格变得非常慢,并且有大量行.
我确实认为我可以通过在rowviewer中包装rowdetail来解决这个问题,但这不起作用,因为细节区域不限于渲染区域.
那么,有人可以提供一些有用的选择吗?我的WPF知识非常少,如果有一些明显的解决方法,那么道歉.
编辑:RowDetailsTemplate
<DataGrid.RowDetailsTemplate>
<DataTemplate >
<Border Background="Gray"
Padding="5,5,5,5" CornerRadius="5">
<TextBlock Background="Transparent"
Foreground="White"
TextWrapping="Wrap"
Text="{Binding Text}"/>
</Border>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
Run Code Online (Sandbox Code Playgroud) .net ×2
android ×2
c ×2
c# ×2
.htaccess ×1
api ×1
bash ×1
checkbox ×1
checked ×1
classloader ×1
collections ×1
concurrency ×1
datagrid ×1
dns ×1
formatting ×1
inputstream ×1
java ×1
jquery ×1
malloc ×1
realloc ×1
redirect ×1
rowdetails ×1
save ×1
scroll ×1
sockets ×1
struct ×1
time ×1
wpf ×1